home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / game / shoot / ADoom_src_1_2.lha / ADoom_src / am_map.c < prev    next >
C/C++ Source or Header  |  1998-03-10  |  36KB  |  1,574 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. //
  18. // $Log:$
  19. //
  20. // DESCRIPTION:  the automap code
  21. //
  22. //-----------------------------------------------------------------------------
  23.  
  24. static const char rcsid[] = "$Id: am_map.c,v 1.4 1997/02/03 21:24:33 b1 Exp $";
  25.  
  26. #include <stdio.h>
  27.  
  28.  
  29. #include "z_zone.h"
  30. #include "doomdef.h"
  31. #include "st_stuff.h"
  32. #include "p_local.h"
  33. #include "w_wad.h"
  34.  
  35. #include "m_cheat.h"
  36. #include "i_system.h"
  37.  
  38. // Needs access to LFB.
  39. #include "v_video.h"
  40.  
  41. // State.
  42. #include "doomstat.h"
  43. #include "r_state.h"
  44.  
  45. // Data.
  46. #include "dstrings.h"
  47.  
  48. #include "am_map.h"
  49.  
  50.  
  51. // For use if I do walls with outsides/insides
  52. #define REDS            (256-5*16)
  53. #define REDRANGE        16
  54. #define BLUES           (256-4*16+8)
  55. #define BLUERANGE       8
  56. #define GREENS          (7*16)
  57. #define GREENRANGE      16
  58. #define GRAYS           (6*16)
  59. #define GRAYSRANGE      16
  60. #define BROWNS          (4*16)
  61. #define BROWNRANGE      16
  62. #define YELLOWS         (256-32+7)
  63. #define YELLOWRANGE     1
  64. #define BLACK           0
  65. #define WHITE           (256-47)
  66.  
  67. // Automap colors
  68. #define BACKGROUND      BLACK
  69. #define YOURCOLORS      WHITE
  70. #define YOURRANGE       0
  71. #define WALLCOLORS      REDS
  72. #define WALLRANGE       REDRANGE
  73. #define TSWALLCOLORS    GRAYS
  74. #define TSWALLRANGE     GRAYSRANGE
  75. #define FDWALLCOLORS    BROWNS
  76. #define FDWALLRANGE     BROWNRANGE
  77. #define CDWALLCOLORS    YELLOWS
  78. #define CDWALLRANGE     YELLOWRANGE
  79. #define THINGCOLORS     GREENS
  80. #define THINGRANGE      GREENRANGE
  81. #define SECRETWALLCOLORS WALLCOLORS
  82. #define SECRETWALLRANGE WALLRANGE
  83. #define GRIDCOLORS      (GRAYS + GRAYSRANGE/2)
  84. #define GRIDRANGE       0
  85. #define XHAIRCOLORS     GRAYS
  86.  
  87. // drawing stuff
  88. #define FB              0
  89.  
  90. #define AM_PANDOWNKEY   KEY_DOWNARROW
  91. #define AM_PANUPKEY     KEY_UPARROW
  92. #define AM_PANRIGHTKEY  KEY_RIGHTARROW
  93. #define AM_PANLEFTKEY   KEY_LEFTARROW
  94. #define AM_ZOOMINKEY    '='
  95. #define AM_ZOOMOUTKEY   '-'
  96. #define AM_STARTKEY     KEY_TAB
  97. #define AM_ENDKEY       KEY_TAB
  98. #define AM_GOBIGKEY     '0'
  99. #define AM_FOLLOWKEY    'f'
  100. #define AM_GRIDKEY      'g'
  101. #define AM_MARKKEY      'm'
  102. #define AM_CLEARMARKKEY 'c'
  103. #define AM_CHANGETYPE   'z' /* 't' conflicts with HU_INPUTTOGGLE, hu_stuff.c */
  104.  
  105. #define AM_NUMMARKPOINTS 10
  106.  
  107. // scale on entry
  108. #define INITSCALEMTOF (.2*FRACUNIT)
  109. // how much the automap moves window per tic in frame-buffer coordinates
  110. // moves 140 pixels in 1 second
  111. #define F_PANINC        4
  112. // how much zoom-in per tic
  113. // goes to 2x in 1 second
  114. #define M_ZOOMIN        ((int) (1.02*FRACUNIT))
  115. // how much zoom-out per tic
  116. // pulls out to 0.5x in 1 second
  117. #define M_ZOOMOUT       ((int) (FRACUNIT/1.02))
  118.  
  119. // translates between frame-buffer and map distances
  120. #define FTOM(x) FixedMul(((x)<<16),scale_ftom)
  121. #define MTOF(x) (FixedMul((x),scale_mtof)>>16)
  122. // translates between frame-buffer and map coordinates
  123. #define CXMTOF(x)  (f_x + MTOF((x)-m_x))
  124. #define CYMTOF(y)  (f_y + (f_h - MTOF((y)-m_y)))
  125.  
  126. // the following is crap
  127. #define LINE_NEVERSEE ML_DONTDRAW
  128.  
  129. typedef struct
  130. {
  131.     int x, y;
  132. } fpoint_t;
  133.  
  134. typedef struct
  135. {
  136.     fpoint_t a, b;
  137. } fline_t;
  138.  
  139. typedef struct
  140. {
  141.     fixed_t             x,y;
  142. } mpoint_t;
  143.  
  144. typedef struct
  145. {
  146.     mpoint_t a, b;
  147. } mline_t;
  148.  
  149. typedef struct
  150. {
  151.     fixed_t slp, islp;
  152. } islope_t;
  153.  
  154.  
  155.  
  156. //
  157. // The vector graphics for the automap.
  158. //  A line drawing of the player pointing right,
  159. //   starting from the middle.
  160. //
  161. #define R ((8*PLAYERRADIUS)/7)
  162. mline_t player_arrow[] = {
  163.     { { -R+R/8, 0 }, { R, 0 } }, // -----
  164.     { { R, 0 }, { R-R/2, R/4 } },  // ----->
  165.     { { R, 0 }, { R-R/2, -R/4 } },
  166.     { { -R+R/8, 0 }, { -R-R/8, R/4 } }, // >---->
  167.     { { -R+R/8, 0 }, { -R-R/8, -R/4 } },
  168.     { { -R+3*R/8, 0 }, { -R+R/8, R/4 } }, // >>--->
  169.     { { -R+3*R/8, 0 }, { -R+R/8, -R/4 } }
  170. };
  171. #undef R
  172. #define NUMPLYRLINES (sizeof(player_arrow)/sizeof(mline_t))
  173.  
  174. #define R ((8*PLAYERRADIUS)/7)
  175. mline_t cheat_player_arrow[] = {
  176.     { { -R+R/8, 0 }, { R, 0 } }, // -----
  177.     { { R, 0 }, { R-R/2, R/6 } },  // ----->
  178.     { { R, 0 }, { R-R/2, -R/6 } },
  179.     { { -R+R/8, 0 }, { -R-R/8, R/6 } }, // >----->
  180.     { { -R+R/8, 0 }, { -R-R/8, -R/6 } },
  181.     { { -R+3*R/8, 0 }, { -R+R/8, R/6 } }, // >>----->
  182.     { { -R+3*R/8, 0 }, { -R+R/8, -R/6 } },
  183.     { { -R/2, 0 }, { -R/2, -R/6 } }, // >>-d--->
  184.     { { -R/2, -R/6 }, { -R/2+R/6, -R/6 } },
  185.     { { -R/2+R/6, -R/6 }, { -R/2+R/6, R/4 } },
  186.     { { -R/6, 0 }, { -R/6, -R/6 } }, // >>-dd-->
  187.     { { -R/6, -R/6 }, { 0, -R/6 } },
  188.     { { 0, -R/6 }, { 0, R/4 } },
  189.     { { R/6, R/4 }, { R/6, -R/7 } }, // >>-ddt->
  190.     { { R/6, -R/7 }, { R/6+R/32, -R/7-R/32 } },
  191.     { { R/6+R/32, -R/7-R/32 }, { R/6+R/10, -R/7 } }
  192. };
  193. #undef R
  194. #define NUMCHEATPLYRLINES (sizeof(cheat_player_arrow)/sizeof(mline_t))
  195.  
  196. #define R (FRACUNIT)
  197. mline_t triangle_guy[] = {
  198.     { { -.867*R, -.5*R }, { .867*R, -.5*R } },
  199.     { { .867*R, -.5*R } , { 0, R } },
  200.     { { 0, R }, { -.867*R, -.5*R } }
  201. };
  202. #undef R
  203. #define NUMTRIANGLEGUYLINES (sizeof(triangle_guy)/sizeof(mline_t))
  204.  
  205. #define R (FRACUNIT)
  206. mline_t thintriangle_guy[] = {
  207.     { { -.5*R, -.7*R }, { R, 0 } },
  208.     { { R, 0 }, { -.5*R, .7*R } },
  209.     { { -.5*R, .7*R }, { -.5*R, -.7*R } }
  210. };
  211. #undef R
  212. #define NUMTHINTRIANGLEGUYLINES (sizeof(thintriangle_guy)/sizeof(mline_t))
  213.  
  214.  
  215.  
  216.  
  217. static int      cheating = 0;
  218. static int      grid = 0;
  219.  
  220. static int      leveljuststarted = 1;   // kluge until AM_LevelInit() is called
  221.  
  222. boolean         automapactive = false;
  223.  
  224. static int      finit_width;
  225. static int      finit_height;
  226.  
  227. extern int      viewwidth; /* CDE'98 - Need this for maponhu */
  228. extern int      viewheight; /* CDE'98 - Need this for maponhu */
  229. extern int      viewwindowx; /* CDE'98 - Need this for maponhu */
  230. extern int      viewwindowy; /* CDE'98 - Need this for maponhu */
  231.  
  232. int      wx; /* CDE'98 - x offset from view */
  233. int      wy; /* CDE'98 - y offset from view */
  234.  
  235. // location of window on screen
  236. static int      f_x;
  237. static int      f_y;
  238.  
  239. // size of window on screen
  240. static int      f_w;
  241. static int      f_h;
  242.  
  243. static int      lightlev;               // used for funky strobing effect
  244. static byte*    fb;                     // pseudo-frame buffer
  245. static int      amclock;
  246.  
  247. static mpoint_t m_paninc; // how far the window pans each tic (map coords)
  248. static fixed_t  mtof_zoommul; // how far the window zooms in each tic (map coords)
  249. static fixed_t  ftom_zoommul; // how far the window zooms in each tic (fb coords)
  250.  
  251. static fixed_t  m_x, m_y;   // LL x,y where the window is on the map (map coords)
  252. static fixed_t  m_x2, m_y2; // UR x,y where the window is on the map (map coords)
  253.  
  254. //
  255. // width/height of window on map (map coords)
  256. //
  257. static fixed_t  m_w;
  258. static fixed_t  m_h;
  259.  
  260. // based on level size
  261. static fixed_t  min_x;
  262. static fixed_t  min_y; 
  263. static fixed_t  max_x;
  264. static fixed_t  max_y;
  265.  
  266. static fixed_t  max_w; // max_x-min_x,
  267. static fixed_t  max_h; // max_y-min_y
  268.  
  269. // based on player size
  270. static fixed_t  min_w;
  271. static fixed_t  min_h;
  272.  
  273.  
  274. static fixed_t  min_scale_mtof; // used to tell when to stop zooming out
  275. static fixed_t  max_scale_mtof; // used to tell when to stop zooming in
  276.  
  277. // old stuff for recovery later
  278. static fixed_t old_m_w, old_m_h;
  279. static fixed_t old_m_x, old_m_y;
  280.  
  281. // old location used by the Follower routine
  282. static mpoint_t f_oldloc;
  283.  
  284. // used by MTOF to scale from map-to-frame-buffer coords
  285. static fixed_t scale_mtof = INITSCALEMTOF;
  286. // used by FTOM to scale from frame-buffer-to-map coords (=1/scale_mtof)
  287. static fixed_t scale_ftom;
  288.  
  289. static player_t *plr; // the player represented by an arrow
  290.  
  291. static patch_t *marknums[10]; // numbers used for marking by the automap
  292. static mpoint_t markpoints[AM_NUMMARKPOINTS]; // where the points are
  293. static int markpointnum = 0; // next point to be assigned
  294.  
  295. static int followplayer = 1; // specifies whether to follow the player around
  296.  
  297. // Dehacked
  298. unsigned char cheat_amap_seq[] = { 0xb2, 0x26, 0x26, 0x2e, 0xff };
  299. static cheatseq_t cheat_amap = { cheat_amap_seq, 0 };
  300.  
  301. static boolean stopped = true;
  302.  
  303. extern boolean viewactive;
  304. extern boolean rotatemap;
  305. extern int maponhu;
  306.  
  307.  
  308. //extern byte screens[][SCREENWIDTH*SCREENHEIGHT];
  309.  
  310.  
  311.  
  312. void
  313. I_MarkRect
  314. ( int   x,
  315.   int   y,
  316.   int   width,
  317.   int   height );
  318.  
  319. //
  320. // Rotation in 2D.
  321. // Used to rotate player arrow line character.
  322. //
  323. void
  324. AM_rotate
  325. ( fixed_t*      x,
  326.   fixed_t*      y,
  327.   angle_t       a )
  328. {
  329.     fixed_t tmpx;
  330.  
  331.     tmpx =
  332.         FixedMul(*x,finecosine[a>>ANGLETOFINESHIFT])
  333.         - FixedMul(*y,finesine[a>>ANGLETOFINESHIFT]);
  334.     
  335.     *y   =
  336.         FixedMul(*x,finesine[a>>ANGLETOFINESHIFT])
  337.         + FixedMul(*y,finecosine[a>>ANGLETOFINESHIFT]);
  338.  
  339.     *x = tmpx;
  340. }
  341.  
  342. // Calculates the slope and slope according to the x-axis of a line
  343. // segment in map coordinates (with the upright y-axis n' all) so
  344. // that it can be used with the brain-dead drawing stuff.
  345.  
  346. void
  347. AM_getIslope
  348. ( mline_t*      ml,
  349.   islope_t*     is )
  350. {
  351.     int dx, dy;
  352.  
  353.     dy = ml->a.y - ml->b.y;
  354.     dx = ml->b.x - ml->a.x;
  355.     if (!dy) is->islp = (dx<0?-MAXINT:MAXINT);
  356.     else is->islp = FixedDiv(dx, dy);
  357.     if (!dx) is->slp = (dy<0?-MAXINT:MAXINT);
  358.     else is->slp = FixedDiv(dy, dx);
  359.  
  360. }
  361.  
  362. //
  363. //
  364. //
  365. void AM_activateNewScale(void)
  366. {
  367.     if (followplayer)
  368.     {
  369.         m_x = plr->mo->x - m_w/2;
  370.         m_y = plr->mo->y - m_h/2;
  371.     }
  372.  
  373.     m_x += m_w/2;
  374.     m_y += m_h/2;
  375.     m_w = FTOM(f_w);
  376.     m_h = FTOM(f_h);
  377.     m_x -= m_w/2;
  378.     m_y -= m_h/2;
  379.     m_x2 = m_x + m_w;
  380.     m_y2 = m_y + m_h;
  381.  
  382.  
  383.     /* ici */
  384. }
  385.  
  386. //
  387. //
  388. //
  389. void AM_saveScaleAndLoc(void)
  390. {
  391.     old_m_x = m_x;
  392.     old_m_y = m_y;
  393.     old_m_w = m_w;
  394.     old_m_h = m_h;
  395. }
  396.  
  397. //
  398. //
  399. //
  400. void AM_restoreScaleAndLoc(void)
  401. {
  402.  
  403.     m_w = old_m_w;
  404.     m_h = old_m_h;
  405.     if (!followplayer)
  406.     {
  407.         m_x = old_m_x;
  408.         m_y = old_m_y;
  409.     } else {
  410.         m_x = plr->mo->x - m_w/2;
  411.         m_y = plr->mo->y - m_h/2;
  412.     }
  413.     m_x2 = m_x + m_w;
  414.     m_y2 = m_y + m_h;
  415.  
  416.     // Change the scaling multipliers
  417.     scale_mtof = FixedDiv(f_w<<FRACBITS, m_w);
  418.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  419. }
  420.  
  421. //
  422. // adds a marker at the current location
  423. //
  424. void AM_addMark(void)
  425. {
  426.     markpoints[markpointnum].x = m_x + m_w/2;
  427.     markpoints[markpointnum].y = m_y + m_h/2;
  428.     markpointnum = (markpointnum + 1) % AM_NUMMARKPOINTS;
  429.  
  430. }
  431.  
  432. //
  433. // Determines bounding box of all vertices,
  434. // sets global variables controlling zoom range.
  435. //
  436. void AM_findMinMaxBoundaries(void)
  437. {
  438.     int i;
  439.     fixed_t a;
  440.     fixed_t b;
  441.  
  442.     min_x = min_y =  MAXINT;
  443.     max_x = max_y = -MAXINT;
  444.   
  445.     for (i=0;i<numvertexes;i++)
  446.     {
  447.         if (vertexes[i].x < min_x)
  448.             min_x = vertexes[i].x;
  449.         else if (vertexes[i].x > max_x)
  450.             max_x = vertexes[i].x;
  451.     
  452.         if (vertexes[i].y < min_y)
  453.             min_y = vertexes[i].y;
  454.         else if (vertexes[i].y > max_y)
  455.             max_y = vertexes[i].y;
  456.     }
  457.   
  458.     max_w = max_x - min_x;
  459.     max_h = max_y - min_y;
  460.  
  461.     min_w = 2*PLAYERRADIUS; // const? never changed?
  462.     min_h = 2*PLAYERRADIUS;
  463.  
  464.     a = FixedDiv(f_w<<FRACBITS, max_w);
  465.     b = FixedDiv(f_h<<FRACBITS, max_h);
  466.   
  467.     min_scale_mtof = a < b ? a : b;
  468.     max_scale_mtof = FixedDiv(f_h<<FRACBITS, 2*PLAYERRADIUS);
  469.  
  470. }
  471.  
  472.  
  473. //
  474. //
  475. //
  476. void AM_changeWindowLoc(void)
  477. {
  478.     if (m_paninc.x || m_paninc.y)
  479.     {
  480.         followplayer = 0;
  481.         f_oldloc.x = MAXINT;
  482.     }
  483.  
  484.     /* CDE'98 Rotate Map Patch - Rotate paninc or not ?? make your choice ... */
  485. /*
  486.     if(rotatemap)
  487.     {
  488.         fixed_t x,y;
  489.         x=m_paninc.x;
  490.         y=m_paninc.y;
  491.         AM_rotate(&x, &y, ANG90-plr->mo->angle);
  492.         m_x += x;
  493.         m_y += y;
  494.     } else {
  495. */
  496.         m_x += m_paninc.x;
  497.         m_y += m_paninc.y;
  498. /*
  499.     }
  500. */
  501.  
  502.     /* CDE'98  - checking for limit is disabled while in rotate mode */
  503.     /*           should not cause any problem */
  504.     if(!rotatemap)
  505.     {
  506.         if (m_x + m_w/2 > max_x)
  507.             m_x = max_x - m_w/2;
  508.         else if (m_x + m_w/2 < min_x)
  509.             m_x = min_x - m_w/2;
  510.   
  511.         if (m_y + m_h/2 > max_y)
  512.             m_y = max_y - m_h/2;
  513.         else if (m_y + m_h/2 < min_y)
  514.             m_y = min_y - m_h/2;
  515.     }
  516.  
  517.     m_x2 = m_x + m_w;
  518.     m_y2 = m_y + m_h;
  519. }
  520.  
  521. //
  522. //
  523. //
  524.  
  525. #define MAX_HUTYPE 5
  526.  
  527. void AM_initMapSize(void)
  528. {
  529.     /* CDE'98 - Calculate view position and size */
  530.     switch(maponhu)
  531.     {
  532.       case 0:
  533.         wx = 0;
  534.         wy = 0;
  535.         f_w = finit_width;
  536.         f_h = finit_height;
  537.       break;
  538.       case 1:
  539.         wx = viewwindowx;
  540.         wy = viewwindowy;
  541.         f_w = viewwidth;
  542.         f_h = viewheight;
  543.       break;
  544.       case 2:
  545.         wx = viewwindowx+viewwidth/14;
  546.         wy = viewwindowy+viewheight/14;
  547.         f_w = viewwidth/4;
  548.         f_h = viewheight/4;
  549.       break;
  550.       case 3:
  551.         wx = viewwindowx+viewwidth/14;
  552.         wy = viewwindowy+viewheight/14;
  553.         f_w = viewwidth/4;
  554.         f_h = viewwidth/4;
  555.       break;
  556.       case 4:
  557.         wx = viewwindowx+viewwidth/14;
  558.         wy = viewwindowy+viewheight/14;
  559.         f_w = viewwidth/3;
  560.         f_h = viewheight/3;
  561.       break;
  562.  
  563.       default:
  564.         wx = viewwindowx;
  565.         wy = viewwindowy;
  566.         f_w = viewwidth;
  567.         f_h = viewheight;
  568.     }
  569. }
  570.  
  571. void resinit_am_map (void)
  572. {
  573.   finit_width = SCREENWIDTH;
  574.   finit_height = SCREENHEIGHT - 32;
  575. }
  576.  
  577. //
  578. //
  579. //
  580. void AM_initVariables(void)
  581. {
  582.     int pnum;
  583.     static event_t st_notify = { ev_keyup, AM_MSGENTERED };
  584.     fixed_t a;
  585.     fixed_t b;
  586.     fixed_t m_w_old;
  587.  
  588.     automapactive = true;
  589.     fb = screens[0];
  590.  
  591.     f_oldloc.x = MAXINT;
  592.     amclock = 0;
  593.     lightlev = 0;
  594.  
  595.     m_paninc.x = m_paninc.y = 0;
  596.     ftom_zoommul = FRACUNIT;
  597.     mtof_zoommul = FRACUNIT;
  598.  
  599.     // CDE'98 Should make this first to avoid plr=NULL :)
  600.     // Find player to center on initially
  601.     if (!playeringame[pnum = consoleplayer])
  602.         for (pnum=0;pnum<MAXPLAYERS;pnum++)
  603.             if (playeringame[pnum])
  604.                 break;
  605.  
  606.     plr = &players[pnum];
  607.  
  608.     // CDE'98 - Calculate view position and size/scale
  609.     m_w_old = m_w;
  610.     AM_initMapSize();
  611.     m_w = FTOM(f_w);
  612.     m_h = FTOM(f_h);
  613.  
  614.     // CDE'98 Change the scaling multipliers
  615.     if(m_w_old != 0)
  616.     {
  617.         a = FixedDiv(f_w<<FRACBITS, max_w);
  618.         b = FixedDiv(f_h<<FRACBITS, max_h);
  619.  
  620.         min_scale_mtof = a < b ? a : b;
  621.         max_scale_mtof = FixedDiv(f_h<<FRACBITS, 2*PLAYERRADIUS);
  622.  
  623.         scale_mtof = FixedDiv(f_w<<FRACBITS, m_w_old);
  624.         scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  625.         AM_activateNewScale();
  626.     }
  627.  
  628.     // CDE'98 Center on our player
  629.     m_x = plr->mo->x - m_w/2;
  630.     m_y = plr->mo->y - m_h/2;
  631.     AM_changeWindowLoc();
  632.  
  633.     // for saving & restoring
  634.     old_m_x = m_x;
  635.     old_m_y = m_y;
  636.     old_m_w = m_w;
  637.     old_m_h = m_h;
  638.  
  639.     // inform the status bar of the change
  640.     ST_Responder(&st_notify);
  641. }
  642.  
  643. //
  644. // 
  645. //
  646. void AM_loadPics(void)
  647. {
  648.     int i;
  649.     char namebuf[9];
  650.   
  651.     for (i=0;i<10;i++)
  652.     {
  653.         sprintf(namebuf, "AMMNUM%d", i);
  654.         marknums[i] = W_CacheLumpName(namebuf, PU_STATIC);
  655.     }
  656.  
  657. }
  658.  
  659. void AM_unloadPics(void)
  660. {
  661.     int i;
  662.   
  663.     for (i=0;i<10;i++)
  664.         Z_ChangeTag(marknums[i], PU_CACHE);
  665.  
  666. }
  667.  
  668. void AM_clearMarks(void)
  669. {
  670.     int i;
  671.  
  672.     for (i=0;i<AM_NUMMARKPOINTS;i++)
  673.         markpoints[i].x = -1; // means empty
  674.     markpointnum = 0;
  675. }
  676.  
  677.  
  678.  
  679. //
  680. // should be called at the start of every level
  681. // right now, i figure it out myself
  682. //
  683. void AM_LevelInit(void)
  684. {
  685.     leveljuststarted = 0;
  686.  
  687.     f_x = f_y = 0;
  688.  
  689.     AM_initMapSize();
  690.  
  691.     AM_clearMarks();
  692.  
  693.     AM_findMinMaxBoundaries();
  694.     scale_mtof = FixedDiv(min_scale_mtof, (int) (0.7*FRACUNIT));
  695.     if (scale_mtof > max_scale_mtof)
  696.         scale_mtof = min_scale_mtof;
  697.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  698. }
  699.  
  700.  
  701.  
  702.  
  703. //
  704. //
  705. //
  706. void AM_Stop (void)
  707. {
  708.     static event_t st_notify = { 0, ev_keyup, AM_MSGEXITED };
  709.  
  710.     AM_unloadPics();
  711.     automapactive = false;
  712.     ST_Responder(&st_notify);
  713.     stopped = true;
  714. }
  715.  
  716. //
  717. //
  718. //
  719. void AM_Start (void)
  720. {
  721.     static int lastlevel = -1, lastepisode = -1;
  722.  
  723.     if (!stopped) AM_Stop();
  724.     stopped = false;
  725.     if (lastlevel != gamemap || lastepisode != gameepisode)
  726.     {
  727.         AM_LevelInit();
  728.         lastlevel = gamemap;
  729.         lastepisode = gameepisode;
  730.     }
  731.     AM_initVariables();
  732.     AM_loadPics();
  733. }
  734.  
  735. //
  736. // set the window scale to the maximum size
  737. //
  738. void AM_minOutWindowScale(void)
  739. {
  740.     scale_mtof = min_scale_mtof;
  741.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  742.     AM_activateNewScale();
  743. }
  744.  
  745. //
  746. // set the window scale to the minimum size
  747. //
  748. void AM_maxOutWindowScale(void)
  749. {
  750.     scale_mtof = max_scale_mtof;
  751.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  752.     AM_activateNewScale();
  753. }
  754.  
  755.  
  756. //
  757. // Handle events (user inputs) in automap mode
  758. //
  759. boolean
  760. AM_Responder
  761. ( event_t*      ev )
  762. {
  763.  
  764.     int rc;
  765.     static int cheatstate=0;
  766.     static int bigstate=0;
  767.     static char buffer[20];
  768.  
  769.     rc = false;
  770.  
  771.     if (!automapactive)
  772.     {
  773.         if (ev->type == ev_keydown && ev->data1 == AM_STARTKEY)
  774.         {
  775.             AM_Start ();
  776.             /* CDE'98 Map on Headup Patch */
  777.             viewactive = (maponhu != 0);
  778.             rc = true;
  779.         }
  780.     }
  781.  
  782.     else if (ev->type == ev_keydown)
  783.     {
  784.  
  785.         rc = true;
  786.         switch(ev->data1)
  787.         {
  788.           case AM_PANRIGHTKEY: // pan right
  789.             if (!followplayer) m_paninc.x = FTOM(F_PANINC);
  790.             else rc = false;
  791.             break;
  792.           case AM_PANLEFTKEY: // pan left
  793.             if (!followplayer) m_paninc.x = -FTOM(F_PANINC);
  794.             else rc = false;
  795.             break;
  796.           case AM_PANUPKEY: // pan up
  797.             if (!followplayer) m_paninc.y = FTOM(F_PANINC);
  798.             else rc = false;
  799.             break;
  800.           case AM_PANDOWNKEY: // pan down
  801.             if (!followplayer) m_paninc.y = -FTOM(F_PANINC);
  802.             else rc = false;
  803.             break;
  804.           case AM_ZOOMOUTKEY: // zoom out
  805.             mtof_zoommul = M_ZOOMOUT;
  806.             ftom_zoommul = M_ZOOMIN;
  807.             break;
  808.           case AM_ZOOMINKEY: // zoom in
  809.             mtof_zoommul = M_ZOOMIN;
  810.             ftom_zoommul = M_ZOOMOUT;
  811.             break;
  812.           case AM_GOBIGKEY:
  813.             bigstate = !bigstate;
  814.             if (bigstate)
  815.             {
  816.                 AM_saveScaleAndLoc();
  817.                 AM_minOutWindowScale();
  818.             }
  819.             else AM_restoreScaleAndLoc();
  820.             break;
  821.           case AM_FOLLOWKEY:
  822.             followplayer = !followplayer;
  823.             f_oldloc.x = MAXINT;
  824.             plr->message = followplayer ? AMSTR_FOLLOWON : AMSTR_FOLLOWOFF;
  825.             break;
  826.           case AM_GRIDKEY:
  827.             grid = !grid;
  828.             plr->message = grid ? AMSTR_GRIDON : AMSTR_GRIDOFF;
  829.             break;
  830.           case AM_MARKKEY:
  831.             sprintf(buffer, "%s %d", AMSTR_MARKEDSPOT, markpointnum);
  832.             plr->message = buffer;
  833.             AM_addMark();
  834.             break;
  835.           case AM_CLEARMARKKEY:
  836.             AM_clearMarks();
  837.             plr->message = AMSTR_MARKSCLEARED;
  838.             break;
  839.           case AM_CHANGETYPE:
  840.             maponhu++;
  841.             if(maponhu>=MAX_HUTYPE)
  842.               maponhu=0;
  843.             AM_Start ();
  844.             viewactive = (maponhu != 0);
  845.             break;
  846.           case AM_ENDKEY:
  847.             bigstate = 0;
  848.             viewactive = true;
  849.             AM_Stop ();
  850.             break;
  851.  
  852.           default:
  853.             cheatstate=0;
  854.             rc = false;
  855.         }
  856.         if (!deathmatch && cht_CheckCheat(&cheat_amap, ev->data1))
  857.         {
  858.             rc = false;
  859.             cheating = (cheating+1) % 3;
  860.         }
  861.     }
  862.  
  863.     else if (ev->type == ev_keyup)
  864.     {
  865.         rc = false;
  866.         switch (ev->data1)
  867.         {
  868.           case AM_PANRIGHTKEY:
  869.             if (!followplayer) m_paninc.x = 0;
  870.             break;
  871.           case AM_PANLEFTKEY:
  872.             if (!followplayer) m_paninc.x = 0;
  873.             break;
  874.           case AM_PANUPKEY:
  875.             if (!followplayer) m_paninc.y = 0;
  876.             break;
  877.           case AM_PANDOWNKEY:
  878.             if (!followplayer) m_paninc.y = 0;
  879.             break;
  880.           case AM_ZOOMOUTKEY:
  881.           case AM_ZOOMINKEY:
  882.             mtof_zoommul = FRACUNIT;
  883.             ftom_zoommul = FRACUNIT;
  884.             break;
  885.         }
  886.     }
  887.  
  888.     return rc;
  889.  
  890. }
  891.  
  892.  
  893. //
  894. // Zooming
  895. //
  896. void AM_changeWindowScale(void)
  897. {
  898.  
  899.     // Change the scaling multipliers
  900.     scale_mtof = FixedMul(scale_mtof, mtof_zoommul);
  901.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  902.  
  903.     if (scale_mtof < min_scale_mtof)
  904.         AM_minOutWindowScale();
  905.     else if (scale_mtof > max_scale_mtof)
  906.         AM_maxOutWindowScale();
  907.     else
  908.         AM_activateNewScale();
  909. }
  910.  
  911.  
  912. //
  913. //
  914. //
  915. void AM_doFollowPlayer(void)
  916. {
  917.  
  918.     if (f_oldloc.x != plr->mo->x || f_oldloc.y != plr->mo->y)
  919.     {
  920.         m_x = FTOM(MTOF(plr->mo->x)) - m_w/2;
  921.         m_y = FTOM(MTOF(plr->mo->y)) - m_h/2;
  922.         m_x2 = m_x + m_w;
  923.         m_y2 = m_y + m_h;
  924.         f_oldloc.x = plr->mo->x;
  925.         f_oldloc.y = plr->mo->y;
  926.  
  927.         //  m_x = FTOM(MTOF(plr->mo->x - m_w/2));
  928.         //  m_y = FTOM(MTOF(plr->mo->y - m_h/2));
  929.         //  m_x = plr->mo->x - m_w/2;
  930.         //  m_y = plr->mo->y - m_h/2;
  931.  
  932.     }
  933.  
  934. }
  935.  
  936. //
  937. //
  938. //
  939. void AM_updateLightLev(void)
  940. {
  941.     static nexttic = 0;
  942.     //static int litelevels[] = { 0, 3, 5, 6, 6, 7, 7, 7 };
  943.     static int litelevels[] = { 0, 4, 7, 10, 12, 14, 15, 15 };
  944.     static int litelevelscnt = 0;
  945.    
  946.     // Change light level
  947.     if (amclock>nexttic)
  948.     {
  949.         lightlev = litelevels[litelevelscnt++];
  950.         if (litelevelscnt == sizeof(litelevels)/sizeof(int)) litelevelscnt = 0;
  951.         nexttic = amclock + 6 - (amclock % 6);
  952.     }
  953.  
  954. }
  955.  
  956.  
  957. //
  958. // Updates on Game Tick
  959. //
  960. void AM_Ticker (void)
  961. {
  962.  
  963.     if (!automapactive)
  964.         return;
  965.  
  966.     amclock++;
  967.  
  968.     if (followplayer)
  969.         AM_doFollowPlayer();
  970.  
  971.     // Change the zoom if necessary
  972.     if (ftom_zoommul != FRACUNIT)
  973.         AM_changeWindowScale();
  974.  
  975.     // Change x,y location
  976.     if (m_paninc.x || m_paninc.y)
  977.         AM_changeWindowLoc();
  978.  
  979.     // Update light level
  980.     // AM_updateLightLev();
  981.  
  982. }
  983.  
  984.  
  985. //
  986. // Clear automap frame buffer.
  987. //
  988. void AM_clearFB(int color)
  989. {
  990.     memset(fb, color, f_w*f_h);
  991. }
  992.  
  993.  
  994. //
  995. // Automap clipping of lines.
  996. //
  997. // Based on Cohen-Sutherland clipping algorithm but with a slightly
  998. // faster reject and precalculated slopes.  If the speed is needed,
  999. // use a hash algorithm to handle  the common cases.
  1000. //
  1001. boolean
  1002. AM_clipMline
  1003. ( mline_t*      ml,
  1004.   fline_t*      fl )
  1005. {
  1006.     enum
  1007.     {
  1008.         LEFT    =1,
  1009.         RIGHT   =2,
  1010.         BOTTOM  =4,
  1011.         TOP     =8
  1012.     };
  1013.     
  1014.     register    outcode1 = 0;
  1015.     register    outcode2 = 0;
  1016.     register    outside;
  1017.     
  1018.     fpoint_t    tmp;
  1019.     int         dx;
  1020.     int         dy;
  1021.  
  1022.     
  1023. #define DOOUTCODE(oc, mx, my) \
  1024.     (oc) = 0; \
  1025.     if ((my) < 0) (oc) |= TOP; \
  1026.     else if ((my) >= f_h) (oc) |= BOTTOM; \
  1027.     if ((mx) < 0) (oc) |= LEFT; \
  1028.     else if ((mx) >= f_w) (oc) |= RIGHT;
  1029.  
  1030.     
  1031.     // do trivial rejects and outcodes
  1032.     if (ml->a.y > m_y2)
  1033.         outcode1 = TOP;
  1034.     else if (ml->a.y < m_y)
  1035.         outcode1 = BOTTOM;
  1036.  
  1037.     if (ml->b.y > m_y2)
  1038.         outcode2 = TOP;
  1039.     else if (ml->b.y < m_y)
  1040.         outcode2 = BOTTOM;
  1041.     
  1042.     if (outcode1 & outcode2)
  1043.         return false; // trivially outside
  1044.  
  1045.     if (ml->a.x < m_x)
  1046.         outcode1 |= LEFT;
  1047.     else if (ml->a.x > m_x2)
  1048.         outcode1 |= RIGHT;
  1049.     
  1050.     if (ml->b.x < m_x)
  1051.         outcode2 |= LEFT;
  1052.     else if (ml->b.x > m_x2)
  1053.         outcode2 |= RIGHT;
  1054.     
  1055.     if (outcode1 & outcode2)
  1056.         return false; // trivially outside
  1057.  
  1058.     // transform to frame-buffer coordinates.
  1059.     fl->a.x = CXMTOF(ml->a.x);
  1060.     fl->a.y = CYMTOF(ml->a.y);
  1061.     fl->b.x = CXMTOF(ml->b.x);
  1062.     fl->b.y = CYMTOF(ml->b.y);
  1063.  
  1064.     DOOUTCODE(outcode1, fl->a.x, fl->a.y);
  1065.     DOOUTCODE(outcode2, fl->b.x, fl->b.y);
  1066.  
  1067.     if (outcode1 & outcode2)
  1068.         return false;
  1069.  
  1070.     while (outcode1 | outcode2)
  1071.     {
  1072.         // may be partially inside box
  1073.         // find an outside point
  1074.         if (outcode1)
  1075.             outside = outcode1;
  1076.         else
  1077.             outside = outcode2;
  1078.         
  1079.         // clip to each side
  1080.         if (outside & TOP)
  1081.         {
  1082.             dy = fl->a.y - fl->b.y;
  1083.             dx = fl->b.x - fl->a.x;
  1084.             tmp.x = fl->a.x + (dx*(fl->a.y))/dy;
  1085.             tmp.y = 0;
  1086.         }
  1087.         else if (outside & BOTTOM)
  1088.         {
  1089.             dy = fl->a.y - fl->b.y;
  1090.             dx = fl->b.x - fl->a.x;
  1091.             tmp.x = fl->a.x + (dx*(fl->a.y-f_h))/dy;
  1092.             tmp.y = f_h-1;
  1093.         }
  1094.         else if (outside & RIGHT)
  1095.         {
  1096.             dy = fl->b.y - fl->a.y;
  1097.             dx = fl->b.x - fl->a.x;
  1098.             tmp.y = fl->a.y + (dy*(f_w-1 - fl->a.x))/dx;
  1099.             tmp.x = f_w-1;
  1100.         }
  1101.         else if (outside & LEFT)
  1102.         {
  1103.             dy = fl->b.y - fl->a.y;
  1104.             dx = fl->b.x - fl->a.x;
  1105.             tmp.y = fl->a.y + (dy*(-fl->a.x))/dx;
  1106.             tmp.x = 0;
  1107.         }
  1108.  
  1109.         if (outside == outcode1)
  1110.         {
  1111.             fl->a = tmp;
  1112.             DOOUTCODE(outcode1, fl->a.x, fl->a.y);
  1113.         }
  1114.         else
  1115.         {
  1116.             fl->b = tmp;
  1117.             DOOUTCODE(outcode2, fl->b.x, fl->b.y);
  1118.         }
  1119.         
  1120.         if (outcode1 & outcode2)
  1121.             return false; // trivially outside
  1122.     }
  1123.  
  1124.     return true;
  1125. }
  1126. #undef DOOUTCODE
  1127.  
  1128.  
  1129. //
  1130. // Classic Bresenham w/ whatever optimizations needed for speed
  1131. //
  1132. void
  1133. AM_drawFline
  1134. ( fline_t*      fl,
  1135.   int           color )
  1136. {
  1137.     register int x;
  1138.     register int y;
  1139.     register int dx;
  1140.     register int dy;
  1141.     register int sx;
  1142.     register int sy;
  1143.     register int ax;
  1144.     register int ay;
  1145.     register int d;
  1146. /*    
  1147.     static fuck = 0;
  1148.  
  1149.     // For debugging only
  1150.  
  1151.     if (      fl->a.x < 0 || fl->a.x >= f_w
  1152.            || fl->a.y < 0 || fl->a.y >= f_h
  1153.            || fl->b.x < 0 || fl->b.x >= f_w
  1154.            || fl->b.y < 0 || fl->b.y >= f_h)
  1155.     {
  1156.         fprintf(stderr, "fuck %d \r", fuck++);
  1157.         return;
  1158.     }
  1159. */
  1160.  
  1161. #define PUTDOT(xx,yy,cc) fb[(yy+wy)*finit_width+(xx+wx)]=(cc)
  1162.  
  1163.     dx = fl->b.x - fl->a.x;
  1164.     ax = 2 * (dx<0 ? -dx : dx);
  1165.     sx = dx<0 ? -1 : 1;
  1166.  
  1167.     dy = fl->b.y - fl->a.y;
  1168.     ay = 2 * (dy<0 ? -dy : dy);
  1169.     sy = dy<0 ? -1 : 1;
  1170.  
  1171.     x = fl->a.x;
  1172.     y = fl->a.y;
  1173.  
  1174.     if (ax > ay)
  1175.     {
  1176.         d = ay - ax/2;
  1177.         while (1)
  1178.         {
  1179.             PUTDOT(x,y,color);
  1180.             if (x == fl->b.x) return;
  1181.             if (d>=0)
  1182.             {
  1183.                 y += sy;
  1184.                 d -= ax;
  1185.             }
  1186.             x += sx;
  1187.             d += ay;
  1188.         }
  1189.     }
  1190.     else
  1191.     {
  1192.         d = ax - ay/2;
  1193.         while (1)
  1194.         {
  1195.             PUTDOT(x, y, color);
  1196.             if (y == fl->b.y) return;
  1197.             if (d >= 0)
  1198.             {
  1199.                 x += sx;
  1200.                 d -= ay;
  1201.             }
  1202.             y += sy;
  1203.             d += ax;
  1204.         }
  1205.     }
  1206. }
  1207.  
  1208.  
  1209.  
  1210. //
  1211. // Clip lines, draw visible part sof lines.
  1212. //
  1213. void
  1214. AM_drawMline
  1215. ( mline_t*      ml,
  1216.   int           color )
  1217. {
  1218.     static fline_t fl;
  1219.     mline_t     l;
  1220.  
  1221.     /* Rotate Map Patch - CDE 98' */
  1222.     if(rotatemap) {
  1223.         l.a.x = ml->a.x-plr->mo->x;
  1224.         l.a.y = ml->a.y-plr->mo->y;
  1225.         l.b.x = ml->b.x-plr->mo->x;
  1226.         l.b.y = ml->b.y-plr->mo->y;
  1227.  
  1228.         AM_rotate(&l.a.x, &l.a.y, ANG90-plr->mo->angle);
  1229.         AM_rotate(&l.b.x, &l.b.y, ANG90-plr->mo->angle);
  1230.  
  1231.         l.a.x += plr->mo->x;
  1232.         l.a.y += plr->mo->y;
  1233.         l.b.x += plr->mo->x;
  1234.         l.b.y += plr->mo->y;
  1235.  
  1236.         if (AM_clipMline(&l, &fl))
  1237.             AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
  1238.     } else {
  1239.         if (AM_clipMline(ml, &fl))
  1240.             AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
  1241.     }
  1242. }
  1243.  
  1244.  
  1245.  
  1246. //
  1247. // Draws flat (floor/ceiling tile) aligned grid lines.
  1248. //
  1249. void AM_drawGrid(int color)
  1250. {
  1251.     fixed_t x, y;
  1252.     fixed_t start, end;
  1253.     mline_t ml;
  1254.  
  1255.     // Figure out start of vertical gridlines
  1256.     start = m_x;
  1257.     if ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS))
  1258.         start += (MAPBLOCKUNITS<<FRACBITS)
  1259.             - ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS));
  1260.     end = m_x + m_w;
  1261.  
  1262.     // draw vertical gridlines
  1263.     ml.a.y = m_y;
  1264.     ml.b.y = m_y+m_h;
  1265.     for (x=start; x<end; x+=(MAPBLOCKUNITS<<FRACBITS))
  1266.     {
  1267.         ml.a.x = x;
  1268.         ml.b.x = x;
  1269.         AM_drawMline(&ml, color);
  1270.     }
  1271.  
  1272.     // Figure out start of horizontal gridlines
  1273.     start = m_y;
  1274.     if ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS))
  1275.         start += (MAPBLOCKUNITS<<FRACBITS)
  1276.             - ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS));
  1277.     end = m_y + m_h;
  1278.  
  1279.     // draw horizontal gridlines
  1280.     ml.a.x = m_x;
  1281.     ml.b.x = m_x + m_w;
  1282.     for (y=start; y<end; y+=(MAPBLOCKUNITS<<FRACBITS))
  1283.     {
  1284.         ml.a.y = y;
  1285.         ml.b.y = y;
  1286.         AM_drawMline(&ml, color);
  1287.     }
  1288.  
  1289. }
  1290.  
  1291. //
  1292. // Determines visible lines, draws them.
  1293. // This is LineDef based, not LineSeg based.
  1294. //
  1295. void AM_drawWalls(void)
  1296. {
  1297.     int i;
  1298.     static mline_t l;
  1299.  
  1300.     for (i=0;i<numlines;i++)
  1301.     {
  1302.         l.a.x = lines[i].v1->x;
  1303.         l.a.y = lines[i].v1->y;
  1304.         l.b.x = lines[i].v2->x;
  1305.         l.b.y = lines[i].v2->y;
  1306.         if (cheating || (lines[i].flags & ML_MAPPED))
  1307.         {
  1308.             if ((lines[i].flags & LINE_NEVERSEE) && !cheating)
  1309.                 continue;
  1310.             if (!lines[i].backsector)
  1311.             {
  1312.                 AM_drawMline(&l, WALLCOLORS+lightlev);
  1313.             }
  1314.             else
  1315.             {
  1316.                 if (lines[i].special == 39)
  1317.                 { // teleporters
  1318.                     AM_drawMline(&l, WALLCOLORS+WALLRANGE/2);
  1319.                 }
  1320.                 else if (lines[i].flags & ML_SECRET) // secret door
  1321.                 {
  1322.                     if (cheating) AM_drawMline(&l, SECRETWALLCOLORS + lightlev);
  1323.                     else AM_drawMline(&l, WALLCOLORS+lightlev);
  1324.                 }
  1325.                 else if (lines[i].backsector->floorheight
  1326.                            != lines[i].frontsector->floorheight) {
  1327.                     AM_drawMline(&l, FDWALLCOLORS + lightlev); // floor level change
  1328.                 }
  1329.                 else if (lines[i].backsector->ceilingheight
  1330.                            != lines[i].frontsector->ceilingheight) {
  1331.                     AM_drawMline(&l, CDWALLCOLORS+lightlev); // ceiling level change
  1332.                 }
  1333.                 else if (cheating) {
  1334.                     AM_drawMline(&l, TSWALLCOLORS+lightlev);
  1335.                 }
  1336.             }
  1337.         }
  1338.         else if (plr->powers[pw_allmap])
  1339.         {
  1340.             if (!(lines[i].flags & LINE_NEVERSEE)) AM_drawMline(&l, GRAYS+3);
  1341.         }
  1342.     }
  1343. }
  1344.  
  1345. void
  1346. AM_drawLineCharacter
  1347. ( mline_t*      lineguy,
  1348.   int           lineguylines,
  1349.   fixed_t       scale,
  1350.   angle_t       angle,
  1351.   int           color,
  1352.   fixed_t       x,
  1353.   fixed_t       y )
  1354. {
  1355.     int         i;
  1356.     mline_t     l;
  1357.  
  1358.     for (i=0;i<lineguylines;i++)
  1359.     {
  1360.         l.a.x = lineguy[i].a.x;
  1361.         l.a.y = lineguy[i].a.y;
  1362.  
  1363.         if (scale)
  1364.         {
  1365.             l.a.x = FixedMul(scale, l.a.x);
  1366.             l.a.y = FixedMul(scale, l.a.y);
  1367.         }
  1368.  
  1369.         if (angle)
  1370.             AM_rotate(&l.a.x, &l.a.y, angle);
  1371.  
  1372.         l.a.x += x;
  1373.         l.a.y += y;
  1374.  
  1375.         l.b.x = lineguy[i].b.x;
  1376.         l.b.y = lineguy[i].b.y;
  1377.  
  1378.         if (scale)
  1379.         {
  1380.             l.b.x = FixedMul(scale, l.b.x);
  1381.             l.b.y = FixedMul(scale, l.b.y);
  1382.         }
  1383.  
  1384.         if (angle)
  1385.             AM_rotate(&l.b.x, &l.b.y, angle);
  1386.         
  1387.         l.b.x += x;
  1388.         l.b.y += y;
  1389.  
  1390.         AM_drawMline(&l, color);
  1391.     }
  1392. }
  1393.  
  1394. void AM_drawPlayers(void)
  1395. {
  1396.     int         i;
  1397.     player_t*   p;
  1398.     static int  their_colors[] = { GREENS, GRAYS, BROWNS, REDS };
  1399.     int         their_color = -1;
  1400.     int         color;
  1401.  
  1402.     if (!netgame)
  1403.     {
  1404.         if (cheating)
  1405.             AM_drawLineCharacter
  1406.                 (cheat_player_arrow, NUMCHEATPLYRLINES, 0,
  1407.                  plr->mo->angle, WHITE, plr->mo->x, plr->mo->y);
  1408.         else
  1409.             AM_drawLineCharacter
  1410.                 (player_arrow, NUMPLYRLINES, 0, plr->mo->angle,
  1411.                  WHITE, plr->mo->x, plr->mo->y);
  1412.         return;
  1413.     }
  1414.  
  1415.     for (i=0;i<MAXPLAYERS;i++)
  1416.     {
  1417.         their_color++;
  1418.         p = &players[i];
  1419.  
  1420.         if ( (deathmatch && !singledemo) && p != plr)
  1421.             continue;
  1422.  
  1423.         if (!playeringame[i])
  1424.             continue;
  1425.  
  1426.         if (p->powers[pw_invisibility])
  1427.             color = 246; // *close* to black
  1428.         else
  1429.             color = their_colors[their_color];
  1430.         
  1431.         AM_drawLineCharacter
  1432.             (player_arrow, NUMPLYRLINES, 0, p->mo->angle,
  1433.              color, p->mo->x, p->mo->y);
  1434.     }
  1435.  
  1436. }
  1437.  
  1438. void
  1439. AM_drawThings
  1440. ( int   colors,
  1441.   int   colorrange)
  1442. {
  1443.     int         i;
  1444.     mobj_t*     t;
  1445.  
  1446.     for (i=0;i<numsectors;i++)
  1447.     {
  1448.         t = sectors[i].thinglist;
  1449.         while (t)
  1450.         {
  1451.             AM_drawLineCharacter
  1452.                 (thintriangle_guy, NUMTHINTRIANGLEGUYLINES,
  1453.                  16<<FRACBITS, t->angle, colors+lightlev, t->x, t->y);
  1454.             t = t->snext;
  1455.         }
  1456.     }
  1457. }
  1458.  
  1459. void AM_drawMarks(void)
  1460. {
  1461.     int i, fx, fy, w, h;
  1462.     fixed_t x,y;
  1463.  
  1464.  
  1465.     for (i=0;i<AM_NUMMARKPOINTS;i++)
  1466.     {
  1467.         if (markpoints[i].x != -1)
  1468.         {
  1469.             //      w = SWAPSHORT(marknums[i]->width);
  1470.             //      h = SWAPSHORT(marknums[i]->height);
  1471.             w = 5; // because something's wrong with the wad, i guess
  1472.             h = 6; // because something's wrong with the wad, i guess
  1473.  
  1474.             /* CDE'98 Rotate Map Patch - Now rotate marks :) */
  1475.             if(rotatemap)
  1476.             {
  1477.                 x=markpoints[i].x-plr->mo->x;
  1478.                 y=markpoints[i].y-plr->mo->y;
  1479.                 AM_rotate(&x, &y, ANG90-plr->mo->angle);
  1480.                 x += plr->mo->x;
  1481.                 y += plr->mo->y;
  1482.                 fx = CXMTOF(x);
  1483.                 fy = CYMTOF(y);
  1484.             } else {
  1485.                 fx = CXMTOF(markpoints[i].x);
  1486.                 fy = CYMTOF(markpoints[i].y);
  1487.             }
  1488.  
  1489.             if (fx >= f_x  && fx <= f_w - w && fy >= f_y && fy <= f_h - h)
  1490.                 V_DrawPatch(fx+wx, fy+wy, FB, marknums[i]);
  1491.         }
  1492.     }
  1493. }
  1494.  
  1495. void AM_drawCrosshair(int color)
  1496. {
  1497.     /* CDE'98 - Crosshair on the view center whatever size/mode ! */
  1498.  
  1499.  
  1500.     //fb[((viewwidth+2*viewwindowx)*(viewheight+2*viewwindowy+1))/2] = color; // single point for now
  1501.     fb[(viewwidth+2*viewwindowx)*(wy+f_h/2)+(wx+f_w/2)] = color; // single point for now
  1502. }
  1503. /*        wx = viewwindowx;
  1504.         wy = viewwindowy;
  1505.         f_w = viewwidth;
  1506.         f_h = viewheight;*/
  1507.  
  1508. void AM_drawBox(int color, int x, int y, int w, int h)
  1509. {
  1510.     fline_t l;
  1511.     int k;
  1512.  
  1513.     /* First draw the background */
  1514.     l.a.y = y-wy-1;
  1515.     l.b.y = y+h-wy;
  1516.     for(k=x-wx-1; k<x+w-wx; k++)
  1517.     {
  1518.         l.a.x = k;
  1519.         l.b.x = k;
  1520.         AM_drawFline(&l, BLACK);
  1521.     }
  1522.  
  1523.     /* Draw white border */
  1524.     l.a.x = x-wx-1;
  1525.     l.a.y = y-wy-1;
  1526.     l.b.x = x-wx-1;
  1527.     l.b.y = y+h-wy;
  1528.     AM_drawFline(&l, color);
  1529.  
  1530.     l.a.x = x+w-wx;
  1531.     l.a.y = y-wy-1;
  1532.     l.b.x = x+w-wx;
  1533.     l.b.y = y+h-wy;
  1534.     AM_drawFline(&l, color);
  1535.  
  1536.     l.a.x = x-wx-1;
  1537.     l.a.y = y-wy-1;
  1538.     l.b.x = x+w-wx;
  1539.     l.b.y = y-wy-1;
  1540.     AM_drawFline(&l, color);
  1541.  
  1542.     l.a.x = x-wx-1;
  1543.     l.a.y = y+h-wy;
  1544.     l.b.x = x+w-wx;
  1545.     l.b.y = y+h-wy;
  1546.     AM_drawFline(&l, color);
  1547.  
  1548. }
  1549.  
  1550. void AM_Drawer (void)
  1551. {
  1552.     if (!automapactive) return;
  1553.  
  1554.     /* Map On HeadUp Patch - CDE 98' */
  1555.     if(maponhu==0)
  1556.         AM_clearFB(BACKGROUND);
  1557.  
  1558.     if(maponhu>1)
  1559.         AM_drawBox(WHITE, wx, wy, f_w, f_h);
  1560.  
  1561.     if (grid)
  1562.         AM_drawGrid(GRIDCOLORS);
  1563.     AM_drawWalls();
  1564.     AM_drawPlayers();
  1565.     if (cheating==2)
  1566.         AM_drawThings(THINGCOLORS, THINGRANGE);
  1567.     AM_drawCrosshair(XHAIRCOLORS);
  1568.  
  1569.     AM_drawMarks();
  1570.  
  1571.     I_MarkRect(f_x, f_y, f_w, f_h);
  1572.  
  1573. }
  1574.